package org.brownflat.lighthouse;

import org.apache.log4j.Logger;
import org.brownflat.lighthouse.monitor.MonitoringService;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Lighthouse {
	
	private static final Logger LOG = Logger.getLogger(Lighthouse.class);
	
	public static void main(String args[]) {
		Lighthouse lighthouse = new Lighthouse();
		lighthouse.run();
	}
	
	public Lighthouse() {
	}

	public void run() {
		Thread.currentThread().setName("Lighthouse");
        LOG.info("*************************************************");
		LOG.info("Starting Lighthouse...");
        LOG.info("Initializing spring...");
		ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("lighthouse_config.xml");
        LOG.info("Initializing monitoring jobs...");
		MonitoringService service = (MonitoringService) context.getBean("monitoringService");
		service.start();
        LOG.info("Lighthouse started");
        LOG.info("*************************************************");
		
		boolean interrupted = false;
		try {
			while(!interrupted) {
				Thread.sleep(10000);
				LOG.trace("Lighthouse pulse.");
			}
			LOG.info("Lighthouse stopped.");
		} catch (InterruptedException inte) {
			LOG.error(inte);
		}
	}
}
